/**
 * Created by huangying on 16/9/28.
 */

var url_link = "http://118.178.59.93:8080/Motocycle/api/v1/";
var DOMAIN = window.location.host;
var total = "";

var storage = window.localStorage;
var storage_user_id = localStorage.getItem("_storage_user_id");
var storage_is_admin = localStorage.getItem("_storage_is_admin");

var is_admin="";//判断是否为管理员(0:否,1:是)

//获取系统时间
var myDate = new Date();
var year = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
var month = myDate.getMonth() + 1;       //获取当前月份(0-11,0代表1月)
var date = myDate.getDate();        //获取当前日(1-31)

if(date<10){
    date="0"+date;
}
var mytime = year + "-" + month + "-" + date;     //获取当前时间

var winScrollTop = "";
var winWidth = "";
var winHeight = "";
var bodyHeight = "";
var docHeight = "";
var docWidth = "";
var rankNavTop = "";
var usercenterLeftTop = "";
var rightTop="";


var data_motocycle = new Array();


var page = 1;//页码
var rows = "";//显示的行数

var article_id = 0;//文章id
var is_theme = '';//该参数为"1",表明是今日更新页面下的较早发布的内容
var theme_id = '';//排序——————最新发布
var mostSee = '';//排序——————点击最高
var mostComment = '';//排序——————评论最多
var mostLike = '';//排序——————点赞最多

var is_nice = '';//发现——————精华
var sex = '';//发现——————性别

var mototype_id = '';//摩托车类型
var user_id = '';//已登录时的id

var report_target_tag = "";//举报类型对象:0:用户,1:文章
var report_type = "";//举报类型
var report_user_id = "";//举报对象的id
var report_person_user_id = "";//文章 or 评论作者的id,用于举报对象是人的情况下

//dom加载完成后
$(document).ready(function () {
    //header里面的导航主题内容
    header_themes();


    ////搜索历史
    //search_history();//获取cookie记录


    //侧边栏定位
    sideBar();


    //页脚置底
    footerBottom();


    //页脚内容变化
    footer_change();


    //表情包
    faceImg();


    //标签栏颜色
    topicColor();

    user_id=storage_user_id;
    is_admin=storage_is_admin;
    console.log(user_id)
    console.log(is_admin)
    if (user_id) {
        //用户登陆后的详情介绍
        $('.side-pub-thread').show();
        user_info();
    } else {
        //登录
        $('.side-pub-thread').hide();
        loading_info();
    }

    ////显示历史记录
    //$("#header").find('#keyword001').focus(function (event) {
    //    if ($(".search-record-box ul").find('li').length > 0) {
    //        $(".search-record").fadeIn(100);
    //    }
    //});
    ////隐藏历史记录
    //$("#header").find('#keyword001').blur(function (event) {
    //    $(".search-record").fadeOut(100);
    //});

    //回到顶部
    $(".side-bar").find('.go-top').click(function (event) {
        $("html,body").animate({
            scrollTop: "0px"
        }, 500);
    });
    //顶部导航
    $("#header .header-row-1-col-2").find('.nav-topic').mouseenter(function (event) {
        $(".header-topic-label").addClass('header-topic-label-slidedown');
    });
    $("#header .header-row-1-col-2").find('.nav-topic').mouseleave(function (event) {
        $(".header-topic-label").removeClass('header-topic-label-slidedown');
    });

    //个人中心左侧列表栏
    if ($(".usercenter-left").length > 0) {
        usercenterLeftTop = $(".usercenter-left").find('.nav').offset().top;
    }
    //排行榜
    if ($(".rank-nav").length > 0) {
        rankNavTop = $('.rank-nav').offset().top;
    }
});

//页面滚动时执行
window.onscroll = function () {
    //发帖按钮
    sideBar();

    winScrollTop = $(window).scrollTop();
    winHeight = $(window).height();
    bodyHeight = $(document).height();

    //头部导航
    if (winScrollTop >= 140) {
        $("#header").find('.header-row-1').addClass('header-row-1-show');
    }
    else {
        $("#header").find('.header-row-1').removeClass('header-row-1-show');
    }

    //排行榜顶部
    if ($(".rank-nav").length > 0) {
        if (winScrollTop >= rankNavTop) {
            $(".rank-nav").addClass('rank-nav-fixed');
        }
        else {
            $(".rank-nav").removeClass('rank-nav-fixed');
        }
    }
    //帖子右侧的作者信息
    if ($('.thread-right').length > 0) {
        threadRight();
    }
};


//窗口或框架被调整大小时发生。
window.onresize = function () {
    winHeight = $(window).height();
    footerBottom();
    sideBar();
    if ($('.thread-right').length > 0) {
        threadRight();
    }
};


//侧边栏定位
function sideBar() {
    bodyHeight = $("body").height();
    winHeight = $(window).height();
    winWidth = $(window).width();
    winScrollTop = $(document).scrollTop();
    if (winScrollTop >= bodyHeight - winHeight - 236) {//侧边栏定位
        $(".side-bar").css("bottom", winHeight + winScrollTop + 256 - bodyHeight);
    }
    else {
        $(".side-bar").css("bottom", "20px");
    }
    if (winScrollTop > 0) {//显示-隐藏滚动到顶部按钮
        $(".side-bar").find('.go-top').removeClass('go-top-hidden');
    }
    else {
        $(".side-bar").find('.go-top').addClass('go-top-hidden');
    }
    if (winWidth <= 1170) {//窗口宽度变化侧栏水平位置
        $(".side-bar,.side-pub-thread").css({
            "opacity": "0.5",
            "right": "0px"
        });
        $(".side-bar,.side-pub-thread").mouseenter(function (event) {
            $(this).css("opacity", "1");
        });
        $(".side-bar,.side-pub-thread").mouseleave(function (event) {
            $(this).css("opacity", "0.5");
        });
    } else {
        $(".side-bar,.side-pub-thread").css({
            "opacity": "1",
            "right": "auto"
        });
        $(".side-bar,.side-pub-thread").mouseenter(function (event) {
            $(this).css("opacity", "1");
        });
        $(".side-bar,.side-pub-thread").mouseleave(function (event) {
            $(this).css("opacity", "1");
        });
    }
}


//页脚始终置于底部
function footerBottom() {
    winHeight = parseInt($(window).height());
    winWidth = parseInt($(window).width());
    docHeight = parseInt($("body").height());
    docWidth = parseInt($("body").width());
    winScrollTop = parseInt($(document).scrollTop());
    if (winHeight > docHeight) {
        $("#container").css({
            "min-height": winHeight - 388 + "px",
        });
    }
}






//header里面的导航主题内容
function header_themes() {
    $.get(url_link + 'themes', function (data) {
        try {
            var obj = JSON.parse(data);
            var themes_info = '';
            //有数据列表
            if (obj.code == 0) {
                themes_info += "<span><em></em></span>" +
                    "<li class='active all'><a href='#'>每日更新</a></li>";
                $.each(obj.data, function (i, item) {
                    themes_info += "<li><a id=" + item.theme_id + " href='#'>" + item.name + "</a></li>";
                });
                $('.header-topic-label-list').html(themes_info)
            }

        } catch (e) {
        }
    })
}


//定义选题标签颜色
function topicColor() {
    $(".topic-lab").each(function (index, element) {
        var data_mototype_id = $(this).attr("data_mototype_id");
        if (data_mototype_id == "1") {
            $(this).css("background", "#2e4b6b");
            return;
        }
        if (data_mototype_id == "2") {
            $(this).css("background", "#ff68c8");
            return;
        }
        if (data_mototype_id == "3") {
            $(this).css("background", "#3eb7c9");
            return;
        }
        if (data_mototype_id == "4") {
            $(this).css("background", "#729c5c");
            return;
        }
        if (data_mototype_id == "5") {
            $(this).css("background", "#343434");
            return;
        }
        if (data_mototype_id == "6") {
            $(this).css("background", "#ef2f2f");
            return;
        }
        if (data_mototype_id == "7") {
            $(this).css("background", "#85a5c7");
            return;
        }
        if (data_mototype_id == "8") {
            $(this).css("background", "#d07721");
            return;
        }
        if (data_mototype_id == "9") {
            $(this).css("background", "#d6c23b");
            return;
        }
        if (data_mototype_id == "10") {
            $(this).css("background", "#8badb7");
            return;
        }
        if (data_mototype_id == "13") {
            $(this).css("background", "#fe6e00");
            return;
        }
        if (data_mototype_id == "11") {
            $(this).css("background", "#67a7a6");
            return;
        }
        if (data_mototype_id == "12") {
            $(this).css("background", "#676767");
            return;
        }
        if (data_mototype_id == "14") {
            $(this).css("background", "#c37a1b");
            return;
        }
        if (data_mototype_id == "15") {
            $(this).css("background", "#2175d0");
            return;
        }
        if (data_mototype_id == "16") {
            $(this).css("background", "#319892");
            return;
        }
    });
}


//表情包
function faceImg() {
    var reg = /(\[5X:)([0-9]*)(\])/g;
    $("p").each(function (index, el) {
        var pText = $(this).html();
        pText = pText.replace(reg, '<img src="../images/5xface/$2.png" class="xxxxx-face"/>');
        $(this).html(pText)
    });
}


//帖子最终页右侧固定方法
function threadRight() {
    var threadRightHeight = $(".thread-right").height();
    var threadRightUserInfoHeight = $(".thread-right").find('.user-info').height();
    var threadRightGoodsHeight = $(".thread-right").find('.goods').height();
    var threadRightTmallHeight = $(".thread-right").find('.tmall').height();
    if (winHeight > threadRightUserInfoHeight + 350) {
        if (winScrollTop >= threadRightHeight + 100) {
            $(".thread-right .user-info").addClass('user-info-fixed');
            if (winHeight > threadRightUserInfoHeight + threadRightGoodsHeight + 350) {
                $(".thread-right").find('.goods').addClass('goods-fixed');
            } else {
                $(".thread-right").find('.goods').removeClass('goods-fixed');
            }
            if (winHeight < threadRightUserInfoHeight + threadRightGoodsHeight + 350 && winHeight > threadRightUserInfoHeight + threadRightTmallHeight + 350) {
                $(".thread-right").find('.tmall').addClass('tmall-fixed');
            } else {
                $(".thread-right").find('.tmall').removeClass('tmall-fixed');
            }
            if ($('.goods').length < 1 && winHeight > threadRightUserInfoHeight + threadRightTmallHeight + 350) {
                $(".thread-right").find('.tmall').addClass('tmall-fixed');
            }
        }
        else {
            $(".thread-right .user-info").removeClass('user-info-fixed');
            $(".thread-right").find('.goods').removeClass('goods-fixed');
            $(".thread-right").find('.tmall').removeClass('tmall-fixed');
        }
    } else {
        $(".thread-right .user-info").removeClass('user-info-fixed');
        $(".thread-right").find('.goods').removeClass('goods-fixed');
        $(".thread-right").find('.tmall').removeClass('tmall-fixed');
    }
}


//页脚变化
function footer_change() {
    $("#footer").find('.footer-weibo-btn').mouseenter(function (event) {
        $(this).addClass('footer-weibo-btn-active');
        $('.footer-weixin-btn').removeClass('footer-weixin-btn-active');
        $('.footer-taobao-btn').removeClass('footer-taobao-btn-active');
        $("#footer").find('.qrcode').addClass('qrcode-hide');
        $("#footer").find('.weibo-list').addClass('weibo-list-show');
        $("#footer").find('.shop-qrcode').removeClass('shop-qrcode-show');
    });
    $("#footer").find('.footer-weibo-btn').mouseleave(function (event) {
        $(this).removeClass('footer-weibo-btn-active');
        $('.footer-weixin-btn').removeClass('footer-weixin-btn-active');
        $('.footer-taobao-btn').removeClass('footer-taobao-btn-active');
        $("#footer").find('.qrcode').addClass('qrcode-hide');
        $("#footer").find('.weibo-list').removeClass('weibo-list-show');
        $("#footer").find('.shop-qrcode').removeClass('shop-qrcode-show');
    });

    $("#footer").find('.footer-weixin-btn').mouseenter(function (event) {
        $(this).addClass('footer-weixin-btn-active');
        $('.footer-weibo-btn').removeClass('footer-weibo-btn-active');
        $('.footer-taobao-btn').removeClass('footer-taobao-btn-active');
        $("#footer").find('.qrcode').removeClass('qrcode-hide');
        $("#footer").find('.weibo-list').removeClass('weibo-list-show');
        $("#footer").find('.shop-qrcode').removeClass('shop-qrcode-show');
    });
    $("#footer").find('.footer-weixin-btn').mouseleave(function (event) {
        $(this).removeClass('footer-weixin-btn-active');
        $('.footer-weibo-btn').removeClass('footer-weibo-btn-active');
        $('.footer-taobao-btn').removeClass('footer-taobao-btn-active');
        $("#footer").find('.qrcode').addClass('qrcode-hide');
        $("#footer").find('.weibo-list').removeClass('weibo-list-show');
        $("#footer").find('.shop-qrcode').removeClass('shop-qrcode-show');
    });

    $("#footer").find('.footer-taobao-btn').mouseenter(function (event) {
        $(this).addClass('footer-taobao-btn-active');
        $('.footer-weixin-btn').removeClass('footer-weixin-btn-active');
        $('.footer-weibo-btn').removeClass('footer-weibo-btn-active');
        $("#footer").find('.qrcode').addClass('qrcode-hide');
        $("#footer").find('.weibo-list').removeClass('weibo-list-show');
        $("#footer").find('.shop-qrcode').addClass('shop-qrcode-show');
    });
    $("#footer").find('.footer-taobao-btn').mouseleave(function (event) {
        $('.footer-taobao-btn').removeClass('footer-taobao-btn-active');
        $('.footer-weixin-btn').removeClass('footer-weixin-btn-active');
        $('.footer-weibo-btn').removeClass('footer-weibo-btn-active');
        $("#footer").find('.qrcode').addClass('qrcode-hide');
        $("#footer").find('.weibo-list').removeClass('weibo-list-show');
        $("#footer").find('.shop-qrcode').removeClass('shop-qrcode-show');
    });
}




//字数判定方法
function charCount(len, v) {
    thisValue = thisDom.val();
    len = 0;
    v = $.trim(thisValue);
    for (i = 0; i < v.length; i++) {
        if (v.charCodeAt(i) > 256) {
            len += 2;
        } else {
            len++;
        }
    }
    thisLength = len;
}


//帖子标题输入字数控制
function threadTitleInput() {
    charCount();
    var charLength = Math.round(thisLength / 2);
    if (thisLength < 12 && thisLength != 0) {
        thisDom.parent(".title-box").find('.char-limit em').text('还需要至少输入');
        var must = 6 - charLength;
        if (must == 0) {
            must = 1;
        }
        thisDom.parent(".title-box").find('.char-limit i').text(must);
        thisDom.parent(".title-box").find('.char-limit i').css('color', '#ff6600');
        thisDom.parent(".title-box").find('.char-limit b').text('字');
        $('.thread-title').addClass('error-input');
        titleFlag = false;
    } else if (thisLength > 60 && thisLength != 0) {
        thisDom.parent(".title-box").find('.char-limit em').text('已超出');
        thisDom.parent(".title-box").find('.char-limit i').text(Math.abs(30 - charLength));
        thisDom.parent(".title-box").find('.char-limit i').css('color', '#e24343');
        thisDom.parent(".title-box").find('.char-limit b').text('字');
        $('.thread-title').addClass('error-input');
    } else if (thisLength == 0) {
        thisDom.parent(".title-box").find('.char-limit em').text('请输入帖子标题');
        thisDom.parent(".title-box").find('.char-limit i').text('');
        thisDom.parent(".title-box").find('.char-limit b').text('');
        $('.thread-title').removeClass('error-input');
    } else {
        thisDom.parent(".title-box").find('.char-limit em').text('还可以输入');
        thisDom.parent(".title-box").find('.char-limit i').text(30 - charLength);
        thisDom.parent(".title-box").find('.char-limit i').css('color', '#2175d0');
        thisDom.parent(".title-box").find('.char-limit b').text('字');
        $('.thread-title').removeClass('error-input');
        titleFlag = true;
    }
}



//===================================================================================================================//
//                                                        登录                                                        //
//===================================================================================================================//
//用户登陆后的详情介绍
function user_info() {
    $.ajax({
        type: 'get',
        url: url_link + 'users/' + user_id,
        async: false,
        success: function (data) {
            try {
                var obj = JSON.parse(data);
                var user_info = '';
                if (obj.code == 0) {
                    user_info += "<div class='user-info-box'>" +
                        "<a href='http://" + DOMAIN + "/motorcycle/html/center/home.html' target='_blank' class='header-username'>" +
                        "<span class='line-left'>" + obj.data.nickname + "</span>" +
                        "<em></em>" +
                        "</a>" +
                        "<ul class='user-info-list'>" +
                        "<li class='user-data'>" +
                        "<div>" +
                        "<a class='headpic' href='http://" + DOMAIN + "/motorcycle/html/center/home.html' target='_blank'>"
                    if(!obj.data.avatar){
                        user_info +="<img src='http://" + DOMAIN + "/motorcycle/image/base/none.png' style='width: 65px;height: 65px;'>"
                    }else{
                        user_info +="<img src=" + obj.data.avatar + " style='width: 65px;height: 65px;'>"
                    }
                    user_info +="</a>" +
                        "<a href='http://" + DOMAIN + "/motorcycle/html/center/home.html' target='_blank'>" +
                        "<h5>" + obj.data.nickname + "</h5>" +
                        "</a>" +
                        "<p>" + obj.data.sign + "</p>" +
                        "</div>" +
                        "<a target='_blank' class='line-right' id='log_off'>退出登录</a>" +
                        "</li>" +
                        "<li class='user-num'>" +
                        "<ul>" +
                        "<li style='padding-left: 0;'>关注<a href='http://" + DOMAIN + "/motorcycle/html/center/friend.html' target='_blank'>" + obj.data.follow_count + "</a></li>" +
                        "<span class='line'></span>" +
                        "<li class='user-num-2 friend-info'>粉丝<a href='http://" + DOMAIN + "/motorcycle/html/center/fans.html' target='_blank'>" + obj.data.fans_count + "</a></li>" +
                        "<span class='line'></span>" +
                        "<li><i>作品</i><a href='http://" + DOMAIN + "/motorcycle/html/center/thread.html' target='_blank'>" + obj.data.article_count + "</a></li>" +
                        "</ul></li>" +
                        "<li class='user-gratuity'>" +
                        "<div class='gratuity-top'>" +
                        "<span class='my-coins'>共有金币：<i></i><b>" + obj.data.gold + "</b></span>" +
                        "<a href='http://" + DOMAIN + "/motorcycle/html/recharge.html' class='recharge' target='_blank'>充值<i></i></a>" +
                        "</div>" +
                        "<ul class='gratuity-bottom'>";
                    $.each(obj.data.gifttemps, function (i, item) {
                        user_info += "<li data-gifttemp-id='" + item.gifttemp_id + "' data-name='" + item.name + "' data-price='" + item.price + "'>" +
                            "<i><img src=" + item.pic + "></i>" + item.count + "桶</li>"
                    });
                    user_info += "</ul>" +
                        "</li>" +
                        "<li class='user-info'>" +
                        "<a href='http://" + DOMAIN + "/motorcycle/html/center/home.html' target='_blank'><em></em>我的</a>" +
                        "<a href='http://" + DOMAIN + "/motorcycle/html/center/commend.html' target='_blank' class='info-comment'><em></em>评论</a>" +
                        "<a class='info-right info-private' href='#'><em></em>私信</a>" +
                        "<a class='info-bottom info-praise' href='http://" + DOMAIN + "/motorcycle/html/center/gratuityList.html' target='_blank'><em></em>打赏</a>" +
                        "<a class='info-bottom' href='http://" + DOMAIN + "/motorcycle/html/center/thread.html' target='_blank'><em></em>帖子</a>" +
                        "<a class='info-bottom info-right' href='http://" + DOMAIN + "/motorcycle/html/center/drafts.html' target='_blank'><em></em>草稿</a>" +
                        "</li>" +
                        "</ul>" +
                        "</div>" +
                        "<a href='http://" + DOMAIN + "/motorcycle/html/center/redemption.html' target='_blank' class='xbshop-btn'><i></i>我的兑换</a>";
                    $('.header-row-1-col-4').html(user_info)
                }
            } catch (e) {

            }

        }

    })
}


//未登录
function loading_info() {
    var loading = "";
    loading += "<a href='http://" + DOMAIN + "/motorcycle/html/loading.html' class='header-login' style='color: white;padding: 0 20px;'>登录</a>" +
        "<span class='line'></span>" +
        "<a href='http://" + DOMAIN + "/motorcycle/html/register.html' class='header-register' style='color: white;padding: 0 20px;'>注册</a>";
    $('.header-row-1-col-4').html(loading)

}


//退出登录
$(document).on('click','#log_off',function(){
    localStorage.removeItem("_storage_user_id");
    localStorage.removeItem("_storage_is_admin");
    location.reload();
});


//===================================================================================================================//
//                                                        关注                                                        //
//===================================================================================================================//
//关注  or  取消关注
$(document).on('click', '#pay_attention_button', function () {
    var button_info = $(this);
    user_id = button_info.attr('data-user-id');
    target_id = button_info.attr('data-target-id');
    var _html = button_info.html().substring(7, button_info.html().length);
    if (_html == "取消关注") {
        layer.msg('是否要取消对Ta的关注？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function (index) {
                layer.close(index);
                $.ajax({
                    type: 'post',
                    url: url_link + 'follows',
                    data: {
                        user_id: user_id,
                        target_id: target_id
                    },
                    async: false,
                    success: function (data) {
                        var obj = JSON.parse(data);
                        if (obj.code == 0) {
                            layer.msg('取消关注成功!');
                            button_info.removeClass('un-follow-btn');
                            button_info.addClass('follow-btn');
                            button_info.html("<i></i>关注");
                        }
                    }
                })
            }
        });
    } else {
        layer.msg('是否要对Ta进行关注？', {
            time: 0, //不自动关闭
            btn: ['确定', '取消'],
            yes: function (index) {
                layer.close(index);
                $.ajax({
                    type: 'post',
                    url: url_link + 'follows',
                    data: {
                        user_id: user_id,
                        target_id: target_id
                    },
                    async: false,
                    success: function (data) {
                        var obj = JSON.parse(data);
                        if (obj.code == 0) {
                            layer.msg('关注成功!');
                            button_info.removeClass('follow-btn');
                            button_info.addClass('un-follow-btn');
                            button_info.html("<i></i>取消关注");
                        }
                    }
                })
            }
        });
    }
});


//===================================================================================================================//
//                                                        私信                                                        //
//===================================================================================================================//
//发送私信
$(document).on('click','#private_letter_button',function(){
   layer.msg("暂未开通，请通过app使用该功能",{time:3000})
});


//===================================================================================================================//
//                                                        举报                                                        //
//===================================================================================================================//
//点击"举报"按钮
$(document).on('click', '.report-btn', function (event) {
    if (user_id) {
        thisDom = $(this);
        openReport();
        report_person_user_id=$(this).attr('data-report-person-user-id')
    } else {
        layer.msg("您尚未登录，请登录后提交举报信息!")
    }
});


//举报函数
function openReport(threadid, commentid, userid, typeid) {//打开举报层
    threadid = thisDom.attr('threadid');
    commentid = thisDom.attr('commentid');
    userid = thisDom.attr('userid');
    typeid = thisDom.attr('type');
    var reportHtml = '<div id="overlay" class="report-overlay"  threadid="' + threadid + '" commentid="' + commentid + '" userid="' + userid + '" type="' + typeid + '">' +
        '<div class="report">' +
        '<h3>' +
        '举报' +
        '<a href="javascript:;" class="close-report">×</a>' +
        '</h3>' +
        '<div class="report-box">' +
        '<h4>请选择举报的对象：<span>必选</span></h4>' +
        '<table>  ' +
        '<tr>' +
        '<td><input type="radio" name="target" id="wenzhang" value="1"/><label for="wenzhang">文章</label></td>' +
        '<td><input type="radio" name="target" id="zuozhe" value="0" /><label for="zuozhe">作者</label></td>' +
        '</tr>' +
        '</table>' +
        '<h4>请选择举报的原因：<span>必选</span></h4>' +
        '<table>  ' +
        '<tr>' +
        '<td><input type="radio" name="reason" id="renshengongji" value="0" /><label for="renshengongji">人身攻击</label></td>' +
        '<td><input type="radio" name="reason" id="seqingdisu" value="1" /><label for="seqingdisu">色情低俗</label></td>' +
        '<td><input type="radio" name="reason" id="guanggaosaorao" value="2" /><label for="guanggaosaorao">广告骚扰</label></td>' +
        '<td><input type="radio" name="reason" id="zhengzhimingan" value="3" /><label for="zhengzhimingan">政治敏感</label></td>' +
        '</tr>' +
        '<tr>' +
        '<td><input type="radio" name="reason" id="yaoyan" value="4" /><label for="yaoyan">谣言</label></td>' +
        '<td><input type="radio" name="reason" id="zhapian" value="5" /><label for="zhapian">诈骗</label></td>' +
        '<td><input type="radio" name="reason" id="qita" value="6" /><label for="qita">其它</label></td>' +
        '</tr>' +
        '</table>' +
        '<h4>请输入说明：<span>必填</span></h4>' +
        '<textarea placeholder="请输入补充说明" style="color: black;" id="pub-report-content"></textarea>' +
        '<a href="javascript:;" id="pub-report" class="blue-button">确认提交</a>' +
        '</div>' +
        '</div>' +
        '</div>';
    $("#header").before(reportHtml);
    $("body").addClass('body-overlay');
    $(".report-overlay").fadeIn(200);
    $("body").on('click', '.close-report,.success-close', function (event) {
        $(".report-overlay").fadeOut(200, function () {
            $(".report-overlay").remove();
            if ($(".overlay").length <= 0) {
                $('body').removeClass('body-overlay');
            }
        });
    });

}


//举报
$(document).on('click', '#pub-report', function () {
    var content_info = $('#pub-report-content').val();
    report_target_tag = $('input[name="target"]:checked').val();
    report_type = $('input[name="reason"]:checked').val();
    if (report_target_tag == "1") {
        //文章
        report_user_id = article_id_details
    } else {
        report_user_id = report_person_user_id
    }
    if (!report_target_tag) {
        layer.msg("您还没有选择举报的对象!")
    } else if (!report_type) {
        layer.msg("您还没有选择举报的原因!")
    } else if (!content_info) {
        layer.msg("您还没有填写具体的举报原因!")
    } else {
        data_motocycle = {
            user_id: user_id,
            target_id: report_user_id,
            content: content_info,
            type: report_type,
            target_tag: report_target_tag
        };
        $.ajax({
            type: 'post',
            url: url_link + 'reports',
            data: data_motocycle,
            success: function (data) {
                var obj = JSON.parse(data);
                if (obj.code == 0) {
                    layer.msg("举报成功!", {time: 3000})
                    $('#overlay').hide();
                }
            }
        })
    }
});



//===================================================================================================================//
//                                                        搜索                                                        //
//===================================================================================================================//
//按下回车,进行关键字检索
$(document).keypress(function(e) {
    var _text=$('#keyword001').val();
    //将搜索记录写入cookie；

    if(_text){
        window.location.href="http://"+DOMAIN+"/motorcycle/html/search.html?keyword="+_text
    }
});
